package com.ruoyi.gams.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gams.domain.GamsDeviceMedia;
import com.ruoyi.gams.service.IGamsDeviceMediaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备资源Controller
 *
 * @author ruoyi
 */
@Api(tags = "广告系统后台：设备资源")
@RestController
@RequestMapping("/gams/devicemedia")
public class GamsDeviceMediaController extends BaseController
{
    @Autowired
    private IGamsDeviceMediaService gamsDeviceMediaService;

    /**
     * 查询设备资源列表
     */
    @ApiOperation("查询设备资源列表")
    @PreAuthorize("@ss.hasPermi('gams:devicemedia:list')")
    @GetMapping("/list")
    public TableDataInfo list(GamsDeviceMedia gamsDeviceMedia)
    {
        startPage();
        List<GamsDeviceMedia> list = gamsDeviceMediaService.selectGamsDeviceMediaList(gamsDeviceMedia);
        return getDataTable(list);
    }

    /**
     * 导出设备资源列表
     */
    @ApiOperation("导出设备资源列表")
    @PreAuthorize("@ss.hasPermi('gams:devicemedia:export')")
    @Log(title = "导出设备资源列表" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GamsDeviceMedia gamsDeviceMedia)
    {
        List<GamsDeviceMedia> list = gamsDeviceMediaService.selectGamsDeviceMediaList(gamsDeviceMedia);
        ExcelUtil<GamsDeviceMedia> util = new ExcelUtil<>(GamsDeviceMedia.class);
        return util.exportExcel(list, "设备资源数据");
    }

    /**
     * 获取设备资源详细信息
     */
    @ApiOperation("获取设备资源详细信息")
    @PreAuthorize("@ss.hasPermi('gams:devicemedia:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(gamsDeviceMediaService.selectGamsDeviceMediaById(id));
    }

    /**
     * 新增设备资源
     */
    @ApiOperation("新增设备资源")
    @PreAuthorize("@ss.hasPermi('gams:devicemedia:add')")
    @Log(title = "新增设备资源" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GamsDeviceMedia gamsDeviceMedia)
    {
        return toAjax(gamsDeviceMediaService.insertGamsDeviceMedia(gamsDeviceMedia));
    }

    /**
     * 修改设备资源
     */
    @ApiOperation("修改设备资源")
    @PreAuthorize("@ss.hasPermi('gams:devicemedia:edit')")
    @Log(title = "修改设备资源" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GamsDeviceMedia gamsDeviceMedia)
    {
        return toAjax(gamsDeviceMediaService.updateGamsDeviceMedia(gamsDeviceMedia));
    }

    /**
     * 删除设备资源
     */
    @ApiOperation("删除设备资源")
    @PreAuthorize("@ss.hasPermi('gams:devicemedia:remove')")
    @Log(title = "删除设备资源" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(gamsDeviceMediaService.deleteGamsDeviceMediaByIds(ids));
    }
}
